<template>

  <div class="fronthome-box">
    <!--  头部  -->
    <div :class="topclass" class="jp_tabsBox">
      <div style="width: 200px; text-align: center" @click="outHome">
        <img src="../../assets/backlogo.png" style="height: 80px;" >
      </div>
      <div  class="buhuanhang" style="flex: 1;height: 60px;background-color:rgba(240,240,240,0);">
        <el-menu :default-active="'1'" class="el-menu-demo" mode="horizontal" style="background-color:rgba(240,240,240,0);height: 60px;border: none;display: flex;flex-wrap: nowrap;" router>
          <el-menu-item index="/front/shouye" style="background-color:rgba(240,240,240,0);border: none" class="daohang">首页</el-menu-item>
          <el-menu-item index="/front/home" style="background-color:rgba(240,240,240,0);border: none" class="daohang">商城</el-menu-item>
          <el-menu-item index="/front/kecheng" style="background-color:rgba(240,240,240,0);border: none" class="daohang">课程</el-menu-item>
          <el-menu-item  style="background-color:rgba(240,240,240,0);border: none" @click="blankBoke" class="daohang">博客中心</el-menu-item>
          <el-menu-item index="/front/vip" style="background-color:rgba(240,240,240,0);border: none" class="daohang">会员购</el-menu-item>
          <el-menu-item index="/front/Chonzhi" style="background-color:rgba(240,240,240,0);border: none" class="daohang">充值</el-menu-item>
        </el-menu>
      </div>
      <!-- 头像  -->
      <div class="touxiang" style="width: 100px; background-color:rgba(240,240,240,0);margin-right: 30px;margin-top: 8px;">
        <div v-if="!user.username" style="opacity: 1;width: 150px;">
          <div style="display:flex;" class="" @mouseenter="inUser" @mouseleave="outUser">
            <el-dropdown  class="showUser">
              <el-dropdown-menu></el-dropdown-menu>
              <div class="userimg">
                <div class="userimg_tu inline_block dengluimg">
                  <span style="font-weight: 800;font-size: 20px;color: white;">登录</span>
                  <div @mouseenter="inshow" @mouseleave="outshow" v-show="showUser" class="caidan" style="height: 100px; width: 180px;left:-65px;">
                    <el-button style="width: 100%;background-color: #00aeec;border: none;border-radius: 10px;">
                      <router-link to="/NewLogin" style="text-decoration: none;color: white;font-size: 15px;font-weight: 800;">立即登录</router-link>
                    </el-button>
                    <div style="text-align: center;line-height: 30px;font-size: 15px;font-weight: 400;">
                      首次使用？
                      <router-link to="/NewLogin" style="text-decoration: none;color: #00b5e5;">点我注册</router-link>
                    </div>
                  </div>
                </div>
              </div>
            </el-dropdown>
          </div>
        </div>
        <div v-else>
          <div style="display:flex; font-size: 12px" class="" @mouseenter="inUser" @mouseleave="outUser">
            <el-dropdown  class="showUser">
              <el-dropdown-menu></el-dropdown-menu>
              <div class="userimg">
                <div class="userimg_tu2 inline_block">
                  <img class="img2" :src="user.avatarUrl" alt="">
                  <transition name="el-fade-in-linear">
                    <div v-show="showUser" class="caidan2"  @mouseenter="inshow" @mouseleave="outshow" >
                      <div style="height: 50px;width: 100%;"></div>
                      <div style="width:100%;height: 50px;text-align: center;line-height: 50px;"><h2 style=" font-size: 30px;font-weight: 800">{{user.nickname}}</h2></div>
                      <div style="width:100%;color: #9499a0;">
                        <div class="inline_block pingjun bianse">文章</div>
                        <div class="inline_block pingjun bianse">说说</div>
                        <div class="inline_block pingjun bianse">关注</div>
                        <div class="inline_block pingjun bianse">粉丝</div>
                      </div>
                      <div class="genr" @click="$router.push('/front/user')">
                        <span style="float: left;">个人中心</span>
                        <span style="float: right;font-weight: 100;">普通用户</span>
                      </div>
                      <div class="genr" >
                        <span style="float: left;">金币</span>
                        <span style="float: right;font-weight: 100;">0 <span>币</span></span>
                      </div>
                      <div class="genr" >
                        <span style="float: left;">订购会员</span>
                      </div>
                      <div class="genr" >
                        <span style="float: left;">我的购买</span>
                      </div>
                      <div class="genr">
                        <span class="genren" style="text-decoration: none" @click="logOut">退出</span>
                      </div>
                    </div>
                  </transition>
                </div>
              </div>
            </el-dropdown>
          </div>
        </div>
      </div>

      <div style="height: 50px;background-color:rgba(240,240,240,0);">
        <el-menu :default-active="'1'" class="el-menu-demo" mode="horizontal" style="background-color:rgba(240,240,240,0);border: none;padding: 5px;padding-right: 20px;padding-top: 10px;display: flex;flex-wrap: nowrap;" router>
          <el-menu-item index="/front/ShoppingTrolley"
                        style=" background-color:rgba(240,240,240,0);position: relative;border: none; " class="daohang danghangyou">
            <el-badge class="mark"  style="position: absolute;right: 0; top: 0; display: flex;border: none;"  :value="$store.state.shoppingNum" />
            <span style="">购物车</span>
            <img src="../../assets/goods.png" style="width: 30%;" alt="" srcset="">
          </el-menu-item>
          <el-menu-item index="/front/vip" style="border: none;background-color:rgba(240,240,240,0);position: relative;" class="daohang danghangyou">
            <span style="">订购会员</span>
            <img src="../../assets/huiyuan.png" style="left: 42%;"  alt="" srcset="">
          </el-menu-item>
          <el-menu-item index="/front/xinxi" style="border: none;background-color:rgba(240,240,240,0);" class="daohang danghangyou">
            <span>消息</span>
            <img src="../../assets/xinxin.png"  alt="" srcset="">
          </el-menu-item>
          <el-menu-item index="/front/dontai" style="border: none;background-color:rgba(240,240,240,0);" class="daohang danghangyou">
            <span>动态</span>
            <img src="../../assets/dontai.png"  alt="" srcset="">
          </el-menu-item>
          <el-menu-item index="/front/shoucang" style="border: none;background-color:rgba(240,240,240,0);" class="daohang danghangyou">
            <span>收藏</span>
            <img src="../../assets/choucang.png" alt="" srcset="">
          </el-menu-item>
          <el-menu-item index="/front/home" style="border: none;background-color:rgba(240,240,240,0);" class="tougao">
            <img class="bubian" src="../../assets/tougao.png"  alt="">
            投稿
          </el-menu-item>
        </el-menu>
      </div>

    </div>
    <div style="margin-top: 0px;">
      <router-view @refreshUser="getUser"/>
    </div>
  </div>
</template>

<script>
import { log } from 'three';
import {serverIp} from '../../../public/config';

export default {
  name: "FrontHome",

  data(){
    return{
      serverIp: serverIp,
      user:localStorage.getItem("user") ? JSON.parse(localStorage.getItem("user")):{},
      showUser: false,
      pathvalue:'',
      topclass: 'fronthome',
      showdenglu: false,
      bbn:false
    }
  },
  methods:{
    blankBoke(){
      let routeUrl = this.$router.resolve({
        path: "/",
      });
      window.open(routeUrl.href, '_blank');
    },
    openShopping(){
      let routeUrl = this.$router.resolve({
        path: "/front/shoppingTrolley",
      });
      window.open(routeUrl.href, '_blank');
    },
    logOut(){
      // console.log(this)
      this.$store.commit("logoutOn")
      this.$message.info("退出成功")
    },
    getUser(){
      this.request.get("/user/"+this.user.id).then(res=>{
        // console.log("Manage"+res.data)
        this.user = res.data
      })
    },
    outHome(){
      this.$router.push('/front/home')
    },
    //鼠标悬停头像
    inUser(){
      this.showUser =true;
      // console.log(this.showUser);
    },
    //鼠标移出
    outUser(){
      this.sleep(400);
      if(!this.bbn){
        this.showUser =false;
      }
      // console.log(this.showUser);
    },
    sleep(ms) { //sleep延迟方法
      var unixtime_ms = new Date().getTime();
      while(new Date().getTime() < unixtime_ms + ms) {}
    },
    inshow(){
      // console.log('jin');
      this.bbn =true;
      // console.log(this.showUser);
    },
    outshow(){
      // console.log('chu');
      this.bbn=false;
      // console.log(this.showUser);
    }
  },
  watch:{
    'pathvalue':{
      handler(value){
        // console.log("我变化了",value);
        if(value === "/front/shouye"){
          console.log("我是首页")
          this.topclass = 'fronthomeHome';
        }else if(value === "/front/user"){
          this.topclass = 'fronthomeHome2';
        }else{
          this.topclass = 'fronthome';
        }
      }
    }
  },
  created(){
    this.pathvalue = this.$route.path;
  },
  updated(){
    // console.log("updata",this.$route.path);
    this.pathvalue = this.$route.path
  }
}
</script>

<style scoped lang="less">

.item {
  height: 50px;
  float: right;
  top: 10px;
  position: relative;
  margin-right: 60px;
}
/*.item::after{*/
/*  content: '';*/
/*  !* after默认是行内元素，需要修改为块元素 *!*/
/*  display: block;*/
/*  clear: both;*/
/*}*/

.gwcbut{
  font-size: 15px;
  float: right;
  padding-right: 5px;
  overflow: hidden;
  // display: block;
  // display:none;
}

// sup{
//   margin-top: 10px;
// }
.fronthome-box{

  // #app{
  position: relative;
  z-index: 1;
  background-color: #efefef;
  /*背景色*/
  background-image: linear-gradient(90deg, rgba(150, 150, 150, 0.15) 10%, rgba(134, 134, 134, 0) 10%), linear-gradient(0deg, rgba(151, 151, 151, 0.15) 10%, rgba(0, 0, 0, 0) 10%);
  /*rgba(0, 0, 0, 0)，transparent全透明黑*/
  background-size: 18px 18px;
  /*调节格子宽 高*/
  // }
  // background-image: url(../../assets/zhuyebg1.jpg);
  .fronthome{
    box-shadow: rgba(100, 100, 111, 0.3) 0px 7px 29px 0px !important;
    display: flex;
    width: 100%;
    height: 90px;
    border-bottom: 1px solid #e6e6e6;
    background-color: #ffffff;
    //   position: absolute;
    // background-image: url(../../assets/zhuyebg1.jpg);
  }
  .fronthomeHome{
    display: flex;
    width: 100%;
    height: 110px;
    position: absolute;
    border: none;
  }
  .fronthomeHome2{
    display: flex;
    width: 100%;
    height: 80px;
    position: absolute;
    background-color: white;
    border: none;

  }
}

/*头像*/
.touxiang{
  .showUser{
    width: 50px;
    height: 50px;
    cursor: pointer;
    .userimg {
      display: inline-block;
      width: 50px;
      height: 50px;
      position: relative;
      .userimg_tu2 {
        width: 70px;
        height: 70px;
        display: flex;
        justify-content: center;
        align-items: center;
        .img2{
          background-size: contain;
          width: 70px;
          height: 70px;
          border-radius: 50%;
          border: 4px solid white;
          position: relative;
          top: 5px;
          z-index: 2153;
          transition-property: width height;
          transition-duration: 0.2s;
        }

        .caidan2{
          position:absolute;
          width: 250px;
          height: 370px;
          top: 100px;
          opacity: 0;
          left: -85px;
          z-index: 2000;
          border-radius: 10px;
          background-color: white ;
          box-shadow:5px 5px 15px #999;
          transition-duration: 0.2s;
          transition-delay: 0.1s;
        }
      }
      .userimg_tu2:hover .img2{
        margin-top: 100px;
        width: 120px;
        height: 120px;
      }
      .userimg_tu2:hover .caidan2{
        top: 100px;
        opacity: 1;
      }
    }
  }
  .inline_block{
    display: inline-block;
  }
  .pingjun{
    width:62.5px;
    height: 40px;
    font-size: 18px;
    text-align: center;
  }
  .bianse:hover{
    color: #00aeec;
  }
  .genr{
    margin: 0 auto;
    margin-top: 3px;
    padding: 0 10px 0 10px;
    width: 90%;
    height: 40px;
    line-height: 40px;
    border-radius: 8px;
    text-align: center;
    font-size: 15px;
    font-weight: 900;
    .genren{
      color: #61666D;
    }
  }
  .genr:hover{
    background-color: #E3E5E7;
  }
  .userimg_tu {
    width: 50px;
    height: 50px;
    padding-bottom: 20px;
    .caidan{
      position: absolute;
      left: -65px;
      top: 50px;
      height: 100px;
      width: 180px;
      padding: 10px;
      opacity: 0;
      z-index: 2000;
      border-radius: 5px;
      background-color: white ;
      font-size: 10px;
      transition-duration: 0.5s;
      transition-delay: 0.2s;
    }
  }
  .userimg_tu:hover{
    padding-bottom: 20px !important;
  }
  .userimg_tu:hover .caidan{
    opacity: 1;
  }
  .dengluimg{
    width: 50px !important;
    height: 50px !important;
    line-height: 50px;
    background-color: #7dbafe;
    border: 1px solid #7dbafe;
    border-radius: 50%;
    background-size: 50px;
    text-align: center;
    position: relative;
    cursor: pointer;
    transition-duration: 3s;

  }
}

/deep/ .daohang{
  font-size: 20px !important;
  height: 90px;
  line-height: 90px;
  border: none;
}
.danghangyou{
  position: relative;
  img{
    width: 20px;
    position: absolute;left: 35%;top: 10%;
  }
  span{
    position: relative;
    top: 5%;
  }
}
.tougao{
  height: 50px;
  line-height: 50px;
  padding: 0;
  border-radius: 5px;
  padding: 0 20px 0 20px;
  background-color:#7dbafe !important;
  .bubian{
    position: none;
    height: 15px;
    margin-right: 5px;
  }
}

.buhuanhang{
  width: 400px !important;
}
</style>